package com.tanhua.controller;

import com.tanhua.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {
    @Autowired
    private VideoService videoService;


    /**
     * POST/smallVideos
     * 发布视频
     * @return
     */
    @PostMapping
    public ResponseEntity upLoad(@RequestBody MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {
        return videoService.upload(videoFile,videoThumbnail);
    }
    /**
     * GET/smallVideos
     * 视频列表
     */
    @GetMapping
    public ResponseEntity videoList(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize){
        return videoService.videoList(page,pagesize);
    }


    /**
     * POST/smallVideos/:uid/userFocus
     * 视频关注
     * */
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity focus(@PathVariable("uid") Long uid){
        return videoService.focus(uid);
    }
    /**
     * POST/smallVideos/:uid/userUnFocus
     * 取消关注
     * */
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity unFocus(@PathVariable("uid") Long uid){
        return videoService.unFocus(uid);
    }
    /**
     * POST/smallVideos/:id/like
     * 视频点赞
     * */
    @PostMapping("/{videoId}/like")
    public ResponseEntity like(@PathVariable("videoId") String videoId){
        return videoService.like(videoId);
    }

    /**
     * POST/smallVideos/:id/dislike
     *      取消视频点赞
     */
    @PostMapping("/{videoId}/dislike")
    public ResponseEntity dislike(@PathVariable("videoId") String videoId){
        return videoService.dislike(videoId);
    }
}
